<?php
/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

use Webman\Route;
use support\Request;

/*// 加载根目录下的路由配置文件
$routeFiles = glob(base_path() . '/routes/*.php');
foreach ($routeFiles as $file) {
    require_once $file;
}

// 404路由
Route::fallback(function(){
    return json([
        'code' => 404,
        'msg' => '接口不存在'
    ]);
});*/

// API端订单路由
Route::group('/api/order', function () {
    Route::post('create', [app\controller\api\OrderController::class, 'create']);
    Route::get('list', [app\controller\api\OrderController::class, 'list']);
    Route::get('detail/{id}', [app\controller\api\OrderController::class, 'detail']);
    Route::post('cancel/{id}', [app\controller\api\OrderController::class, 'cancel']);
    Route::post('confirm/{id}', [app\controller\api\OrderController::class, 'confirm']);
    // 退款相关路由
    Route::post('refund/apply/{id}', [app\controller\api\OrderController::class, 'refundApply']);
    Route::get('refund/list', [app\controller\api\OrderController::class, 'refundList']);
    Route::get('refund/detail/{id}', [app\controller\api\OrderController::class, 'refundDetail']);
})->middleware([
    app\middleware\JwtMiddleware::class,
]);

// 后台订单路由
Route::group('/admin/order', function () {
    Route::get('index', [app\controller\admin\OrderController::class, 'index']);
    Route::get('show/{id}', [app\controller\admin\OrderController::class, 'show']);
    Route::post('ship/{id}', [app\controller\admin\OrderController::class, 'ship']);
    // 退款相关路由
    Route::get('refund/list', [app\controller\admin\OrderController::class, 'refundList']);
    Route::get('refund/show/{id}', [app\controller\admin\OrderController::class, 'refundShow']);
    Route::post('refund/agree/{id}', [app\controller\admin\OrderController::class, 'refundAgree']);
    Route::post('refund/refuse/{id}', [app\controller\admin\OrderController::class, 'refundRefuse']);
    Route::post('refund/confirm/{id}', [app\controller\admin\OrderController::class, 'refundConfirm']);
    Route::get('refund/statistics', [app\controller\admin\OrderController::class, 'refundStatistics']);
})->middleware([
    app\middleware\AdminJwtMiddleware::class,
]);

// API端优惠券路由
Route::group('/api/coupon', function () {
    Route::get('list', [app\controller\api\CouponController::class, 'list']);
    Route::get('detail/{id}', [app\controller\api\CouponController::class, 'detail']);
    Route::post('receive/{id}', [app\controller\api\CouponController::class, 'receive']);
    Route::get('my', [app\controller\api\CouponController::class, 'my']);
    Route::post('check', [app\controller\api\CouponController::class, 'check']);
})->middleware([
    app\middleware\JwtMiddleware::class,
]);

// 后台优惠券路由
Route::group('/admin/coupon', function () {
    Route::get('list', [app\controller\admin\CouponController::class, 'list']);
    Route::get('detail/{id}', [app\controller\admin\CouponController::class, 'detail']);
    Route::post('store', [app\controller\admin\CouponController::class, 'store']);
    Route::put('update/{id}', [app\controller\admin\CouponController::class, 'update']);
    Route::delete('destroy/{id}', [app\controller\admin\CouponController::class, 'destroy']);
    Route::post('status/{id}', [app\controller\admin\CouponController::class, 'status']);
    Route::get('statistics', [app\controller\admin\CouponController::class, 'statistics']);
})->middleware([
    app\middleware\AdminJwtMiddleware::class,
]);

// API端促销活动路由
Route::group('/api/promotion', function () {
    Route::get('list', [app\controller\api\PromotionController::class, 'list']);
    Route::get('detail/{id}', [app\controller\api\PromotionController::class, 'detail']);
    Route::get('product/list', [app\controller\api\PromotionController::class, 'productList']);
    Route::get('product/detail/{id}', [app\controller\api\PromotionController::class, 'productDetail']);
})->middleware([
    app\middleware\JwtMiddleware::class,
]);

// 后台促销活动路由
Route::group('/admin/promotion', function () {
    Route::get('list', [app\controller\admin\PromotionController::class, 'list']);
    Route::get('detail/{id}', [app\controller\admin\PromotionController::class, 'detail']);
    Route::post('store', [app\controller\admin\PromotionController::class, 'store']);
    Route::put('update/{id}', [app\controller\admin\PromotionController::class, 'update']);
    Route::delete('destroy/{id}', [app\controller\admin\PromotionController::class, 'destroy']);
    Route::post('status/{id}', [app\controller\admin\PromotionController::class, 'status']);
    Route::get('statistics', [app\controller\admin\PromotionController::class, 'statistics']);
    // 促销商品管理
    Route::get('item/list', [app\controller\admin\PromotionController::class, 'itemList']);
    Route::post('item/store', [app\controller\admin\PromotionController::class, 'itemStore']);
    Route::put('item/update/{id}', [app\controller\admin\PromotionController::class, 'itemUpdate']);
    Route::delete('item/destroy/{id}', [app\controller\admin\PromotionController::class, 'itemDestroy']);
})->middleware([
    app\middleware\AdminJwtMiddleware::class,
]);

// 系统命令执行API

// 后台命令执行路由
Route::group('/admin/command', function () {
    Route::post('execute', [app\controller\admin\CommandController::class, 'execute']);
})->middleware([
    app\middleware\AdminJwtMiddleware::class,
]);






